﻿Imports System.Windows.Controls.Primitives

Public Class MatrixEntry
    Inherits Thumb

    Shared Sub New()
        DefaultStyleKeyProperty.OverrideMetadata(GetType(MatrixEntry), New FrameworkPropertyMetadata(GetType(MatrixEntry)))
    End Sub



    Public Property Value As Integer
        Get
            Return DirectCast(GetValue(ValueProperty), Integer)
        End Get
        Set(ByVal value As Integer)
            SetValue(ValueProperty, value)
        End Set
    End Property

    Public Shared ReadOnly ValueProperty As DependencyProperty = DependencyProperty.Register( _
        "Value", GetType(Integer), GetType(MatrixEntry),
        New FrameworkPropertyMetadata(0))



    Public Property IsSelfFeedBack As Boolean
        Get
            Return DirectCast(GetValue(IsSelfFeedBackProperty), Boolean)
        End Get
        Set(ByVal value As Boolean)
            SetValue(IsSelfFeedBackProperty, value)
        End Set
    End Property

    Public Shared ReadOnly IsSelfFeedBackProperty As DependencyProperty = DependencyProperty.Register( _
        "IsSelfFeedBack", GetType(Boolean), GetType(MatrixEntry),
        New FrameworkPropertyMetadata(False))



    Public Property OperatorName As String
        Get
            Return DirectCast(GetValue(OperatorNameProperty), String)
        End Get
        Set(ByVal value As String)
            SetValue(OperatorNameProperty, value)
        End Set
    End Property

    Public Shared ReadOnly OperatorNameProperty As DependencyProperty = DependencyProperty.Register( _
        "OperatorName", GetType(String), GetType(MatrixEntry),
        New FrameworkPropertyMetadata(""))



    Private origValue As Integer

    Private Sub MatrixEntry_DragStarted(sender As Object, e As DragStartedEventArgs) Handles Me.DragStarted
        origValue = Value
    End Sub

    Private Sub MatrixEntry_DragDelta(sender As Object, e As DragDeltaEventArgs) Handles Me.DragDelta
        Dim _value = CInt(-e.VerticalChange + e.HorizontalChange) * 2 + origValue
        If _value < 0 Then _value = 0
        If _value > 999 Then _value = 999
        Value = _value
    End Sub

    Private Sub MatrixEntry_DragCompleted(sender As Object, e As DragCompletedEventArgs) Handles Me.DragCompleted

    End Sub

End Class


